import axios from 'axios'
const baseURL = "http://megasensing.cn:4000"
// const deviceNameList:string[] = ["紫外","红外","温度","湿度","压力"]
let flog = true
// 控制阀门
//@ts-ignore
self.date = new Date()
self.onmessage = (e) => {
  console.log(e.data)
   let data = JSON.parse(e.data)
   let userList = data.phoneList
   let module_id = data.module_id
   let type_id = data.type
   let errorValue = data.value
   //@ts-ignore
   if (flog || (new Date() - self.date > 10000)) {
    flog = false
    if (userList.length === 1) {
        // 单发短信
        console.log("单发短信")
        axios.post(baseURL+"/socket/sendMsg",{ tel:userList[0].phone,type:type_id,region: module_id,value:errorValue }).then(res => {
          console.log(res.data)
        })
      } else {
        // 群发短信
        console.log("群发短信")
        //@ts-ignore
       axios.post(baseURL+"/socket/sendMulMsg",{tel:userList.map(item => item.phone),type:type_id,region: module_id,value:errorValue}).then(res => {
        console.log(res.data)
      })
     }
     //@ts-ignore
     self.date = new Date()
   }
  
}